from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, Date, Numeric, Index, Text

from config.database import Base


class KylinFutureAccountDaily(Base):
    """
    期货账户资金日报表
    """

    __tablename__ = 'kylin_future_account_daily'
    __table_args__ = (
        Index('idx_account_date', 'account_code', 'settlement_date', unique=True),
        Index('idx_account_code', 'account_code'),
        Index('idx_settlement_date', 'settlement_date'),
        {'comment': '期货账户资金日报表'}
    )
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键id')
    account_code = Column(String(20), nullable=False, comment='账户代码')
    settlement_date = Column(Date, nullable=False, comment='结算日期')
    previous_balance_day = Column(Numeric(15, 2), nullable=False, default=0, comment='上日结存(逐日盯市)')
    previous_balance_trade = Column(Numeric(15, 2), nullable=False, default=0, comment='上日结存(逐笔对冲)')
    daily_deposit_withdrawal = Column(Numeric(15, 2), nullable=False, default=0, comment='当日存取合计')
    daily_profit_day = Column(Numeric(15, 2), nullable=False, default=0, comment='当日盈亏(逐日盯市)')
    daily_balance_day = Column(Numeric(15, 2), nullable=False, default=0, comment='当日结存(逐日盯市)')
    close_profit_trade = Column(Numeric(15, 2), nullable=False, default=0, comment='平仓盈亏(逐笔对冲)')
    daily_balance_trade = Column(Numeric(15, 2), nullable=False, default=0, comment='当日结存(逐笔对冲)')
    float_profit_trade = Column(Numeric(15, 2), nullable=False, default=0, comment='浮动盈亏(逐笔对冲)')
    daily_fee = Column(Numeric(15, 2), nullable=False, default=0, comment='当日手续费')
    equity = Column(Numeric(15, 2), nullable=False, default=0, comment='客户权益')
    margin_used = Column(Numeric(15, 2), nullable=False, default=0, comment='保证金占用')
    available_funds = Column(Numeric(15, 2), nullable=False, default=0, comment='可用资金')
    risk_ratio = Column(Numeric(8, 4), nullable=False, default=0, comment='风险度')
    create_time = Column(DateTime, default=datetime.now, comment='创建时间')
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')